<template>
  <div class="video-list">
    <ul class="video-ul">
      <li class="video-item" 
        v-for="(item,index) in VideoData" 
        :key="index" 
        @click="showVideo(index)"  
        @mouseenter="videoPlay(index)" 
        @mouseleave="videoPause(index)"
      >
        <video class="video-win" :ref="'video' + index" muted width="240" height="135">
          <source :src="item.fileurl" type="video/mp4">
          您的浏览器不支持 HTML5 video 标签。
        </video>
        <div class="video-mubu" title="点击播放">
            <svg class="icon" aria-hidden="true" >
              <use xlink:href="#icon-shipin"></use>
            </svg>
        </div>
        <div class="video-text">
          <b>视频</b>
          <span>{{item.title}}</span>
        </div>
      </li>
    </ul>
    <video-win :videoData="videoData" v-if="videoData.videoWinFlag"></video-win>
  </div>
</template>

<script>
import VideoWin from './win.vue'
export default {
  name: 'VideoItem',

  data() {
    return {
      // 要播放的视频
      videoData: {
        videoSrc: '', // 视频路径
        videoWinFlag: false // 视频窗口是否打开
      },
      timer: null // 播放定时器
    };
  },

  props:{
    // 所有视频数据集
    VideoData: Array
  },

  mounted() {
    
  },

  methods: {
    // 短暂播放视频8s
    videoPlay(index){
      let video = this.$refs['video' + index][0]
      this.videoFlag = true
      video.play()
      clearTimeout(this.timer)
      this.timer = setTimeout(()=>{
        video.pause()
      },8000)
      
    },
    // 暂停视频
    videoPause(index){
      let video = this.$refs['video' + index][0]
      this.videoFlag = false
      video.pause()
    },
    // 显示播放视频
    showVideo(index){
      this.videoData.videoWinFlag = true
      this.videoData.videoSrc = this.VideoData[index].fileurl
    }
  },
  
  components: {
    VideoWin
  }
};
</script>

<style scoped>
.video-ul{
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  align-items: center;
}
.video-item{
  position: relative;
  cursor: pointer;
  width: 240px;
  vertical-align: top;
  text-align: center;
  margin: 20px 10px;
}
.video-item .video-mubu{
  background-color: rgba(0, 0, 0, .7);
  height: 135px;
  line-height: 135px;
  font-size: 50px;
  text-align: center;
  cursor: pointer;
  position: absolute;
  top: 0;
  left: 0;
  width: 240px;
  display: none;
}
.video-item:hover .video-mubu{
  display: block;
}
.video-text span{
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  float: left;
  width: 200px;
  padding-right: 20px;
}
.video-text b{
  font-size: 11px;
  border: 1px solid rgb(114, 184, 250);
  padding: 1px;
  margin-right: 8px;
  color: rgb(88, 88, 245);
  float: left;
}
.video-item:hover .video-text span{
  color: red;
}
</style>